<template >
  <div class="app-container conserveRecord">
    <el-form :model="selectForm" ref="queryForm" :inline="true" label-width="120px">
      <el-form-item label="所属公司：">
        <treeselect v-if="deptOptions" class="option" v-model="selectForm.departmentId" :options="deptOptions" placeholder="请选择所属部门" />
      </el-form-item>
      <el-form-item label="设备名称：">
        <el-input size="small"  v-model="selectForm.deviceName" placeholder="请输入设备名称" clearable/>
      </el-form-item>
      <el-form-item label="设备编号：">
        <el-input size="small"  v-model="selectForm.deviceCoder" placeholder="请输入设备编号" clearable/>
      </el-form-item>
      <el-form-item label="计划日期：">
        <el-date-picker
          size="small"
          v-model="selectDate"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="dateChange"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="养护人：">
        <el-input size="small"  v-model="selectForm.chargeUserName" placeholder="请输入养护人" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="primary" icon="el-icon-search" @click="selectForm.pageNum=1;getList();">搜索</el-button>
        <el-button size="mini" type="success" icon="el-icon-plus" @click="add">添加</el-button>

      </el-form-item>
    </el-form>
    <el-table v-loading="loading" ref="singleTable" :data="list" stripe border  >
      <el-table-column align="center" type="index" label="序号" width="55"/>
      <el-table-column align="center" label="养护计划编号" width="150"  prop="planCoder">
        <template slot-scope="scope">
          <div class="bule"  @click="details(scope.row)">{{scope.row.planCoder}}</div>
        </template>
      </el-table-column>
      <el-table-column label="计划时间" align="center" prop="conservePlanDate" >
        <template slot-scope="scope">
          <span>{{ scope.row.conservePlanDate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行时间" align="center" prop="executeDate" >
        <template slot-scope="scope">
          <span>{{ scope.row.executeDate }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备名称" prop="deviceName"  />
      <el-table-column align="center" label="存放地址" prop="siteName"  />
      <el-table-column align="center" label="养护类型" prop="conserveTypeName">

      </el-table-column>
      <el-table-column align="center" label="养护人" prop="chargeUserName" />
      <el-table-column align="center" label="养护费用" prop="conserCost" />
    </el-table>
    <pagination
      :total="total"
      :page.sync="selectForm.pageNum"
      :limit.sync="selectForm.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import {treeselect } from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import {conserveRecordList} from '@/api/curing/index'
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  export default {
    name: "conserveRecord.vue",
    components:{
      Treeselect,
    },
    data() {
      return {
        treedata: [],
        defaultProps: {
          children: "children",
          label: "label"
        },
        deptOptions:'',

        loading: false,//加载
        selectForm: {
          departmentId:undefined,//所属公司
          chargeUserName:null,
          deviceCoder:null,
          deviceName:null,
          endDate:null,
          startDate:null,
          pageNum: 1,
          pageSize: 10,
        },//查询条件
        list: [],//数据
        total: 0,
        selectDate: '',//时间
      }
    },
    created() {
      this.getTreeselect()
      this.getList()
    },
    methods: {
      /** 查询类别下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },

      getList() {
        conserveRecordList(this.selectForm).then((res)=>{
          if(res.code==200){
            this.list=res.rows
            this.total=res.total
          }
        })
      },
      //更改时间
      dateChange() {
        this.selectForm.startDate = this.selectDate&&this.selectDate[0]||null
        this.selectForm.endDate = this.selectDate&&this.selectDate[1]||null
      },
      add() {
        this.$router.push({path:'/conserve/conserveRecordAdd'});
      },

      details(row){
        this.$router.push({path:'/conserve/conserveRecordDetail',query:{id:row.id}});
      },

    }
  }
</script>

<style  lang="scss">
  .conserveRecord {
    .bule {
      color: #2196F3;
      cursor: pointer;
    }
    .btn-blue{
      background: deepskyblue;
      color: #fff;
    }
    .option{
      width: 200px;
      height:32px;
      .vue-treeselect__control{
        line-height: 32px;
        height:32px !important;
      }
    }
  }
</style>
